//
//  PlanInfo.m
//  SportSocial
//
//  Created by yull on 15/2/3.
//  Copyright (c) 2015年 yull. All rights reserved.
//

#import "PlanInfo.h"

@implementation PlanInfo

+ (instancetype)planInfoWithResutlSet:(FMResultSet *)resultSet
{
    PlanInfo *planInfo = [[PlanInfo alloc] init];
    planInfo.dbId = [resultSet longLongIntForColumn:@"id"];
    planInfo.icon = [resultSet stringForColumn:@"icon"];
    planInfo.year = [resultSet intForColumn:@"year"];
    planInfo.month = [resultSet intForColumn:@"month"];
    planInfo.day = [resultSet intForColumn:@"day"];

    planInfo.sport_name = [resultSet stringForColumn:@"sport_name"];
    planInfo.calorie = [resultSet intForColumn:@"calorie"];
    planInfo.distance = [resultSet doubleForColumn:@"distance"];
    planInfo.status = [resultSet intForColumn:@"status"];
    planInfo.address = [resultSet stringForColumn:@"address"];
    planInfo.start_date = [resultSet longLongIntForColumn:@"start_date"];
    planInfo.end_date = [resultSet longLongIntForColumn:@"end_date"];
    planInfo.max_speed = [resultSet doubleForColumn:@"max_speed"];
    planInfo.avg_speed = [resultSet doubleForColumn:@"avg_speed"];
    planInfo.latitude = [resultSet doubleForColumn:@"latitude"];
    planInfo.longitude = [resultSet doubleForColumn:@"longitude"];
    return planInfo;
}

- (NSString *)convertStartDateToString
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:self.start_date];
    
    return [dateFormatter stringFromDate:date];
}

- (NSString *)convertEndDateToString
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:self.end_date];
    
    return [dateFormatter stringFromDate:date];
}

- (NSString *)getIconImageName
{
    NSArray *iconArray = @[@"basketball_icon_normal",@"football_icon_normal",@"running_icon_normal",@"swimming_icon_normal",@"billiards_icon_normal",@"tennis_icon_normal",@"table_icon_normal"];

    NSArray *titleArray = @[@"篮球",@"足球",@"跑步",@"游泳",@"台球",@"网球",@"乒乓球"];
    
    NSArray *unFinishedIconArray = @[@"basketball_icon_disable",@"football_icon_disable",@"running_icon_disable",@"swimming_icon_disable",@"billiards_icon_disable",@"tennis_icon_disable",@"table_icon_disable"];
    
    NSInteger i=0;
    for (;i<titleArray.count;i++) {
        NSString *name = [titleArray objectAtIndex:i];
        if ([name isEqualToString:self.sport_name]) {
            if (self.status == PlanInfoStatusEnd) {
                return [iconArray objectAtIndex:i];
            }else {
                return [unFinishedIconArray objectAtIndex:i];
            }
            break;
        }
    }
    
    return nil;
}
@end
